
var request = require('request');
var fs = require('fs');
const path = require("path");
const mkdirp =require('mkdirp')
const superagent = require('superagent');
var url = 'https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200f1b0000be7lkecmavf1ah0r6o6g&line=0'
superagent
  .get(url)
  .set({
      'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
  })
  .end((err,res) => {
      if(err){
          console.log(err);
          return;
      }
      console.log('页面已加载加载！')
      console.log(res.redirects[0])
      download(res.redirects[0], './video/121')
  })

function download (url, path) {
  request(url).on('error', function(err) {
     console.log(err)
  // }).pipe(fs.createWriteStream(path+".mp4")).on('finish',()=>{
  }).pipe(fs.createWriteStream(path+".mp4")).on('finish',()=>{
      console.log('视频下载成功：%s');
  })
}

